<?php
//url化
function replaceSpaces($S, $length) {
    $S = substr($S,0,$length);
    $S = str_replace(array(" "),array("%20"),$S);
    return $S;
}

echo replaceSpaces("  ",1);